import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;

public class Main {
	public static void main(String[] args) throws Exception {
		Properties systemProperties = System.getProperties();
//		systemProperties.setProperty("http.proxyHost","wwwgate0-ch.mot.com");
//		systemProperties.setProperty("http.proxyPort","1080");

		
		HttpURLConnection con = null;
		BufferedReader br = null;
		
		String s = null;
		
       String   purl="http://zc.qq.com/chs/index.html?type=1";
		
		con = (HttpURLConnection) (new URL(purl)).openConnection();
		HttpURLConnection.setFollowRedirects(true);

		con.addRequestProperty("Accept", "*/*");
		con.addRequestProperty("Accept-Language", "zh-cn");
		con.addRequestProperty(
				"User-Agent",
				"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; CIBA; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
		// con.addRequestProperty("Accept-Encoding","gzip, deflate");
		// con.addRequestProperty("Host","localhost");
		con.addRequestProperty("Connection", "Keep-Alive");
		// con.addRequestProperty("Cookie","JSESSIONID=abclVDaPju4__9wPhmHts");

//		br=new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
		br=new BufferedReader(new InputStreamReader(new FileInputStream("qq.txt"),"utf-8"));
		int i=0;
		 HttpClient httpclient= new DefaultHttpClient();  
		 Pattern p=Pattern.compile("<img\\s+id=\"code_img\"[^<>]+src=\"([^<>\"]*)\"[^<>]+>");
while((s = br.readLine())!= null) {
	


Matcher m2=p.matcher(s);
 if(m2.find()){
	   System.out.println("find-->"+m2.group(1));
	String st=ImageCode.getCode(m2.group(1), httpclient);
 
	  if(st==null)
	 System.out.println("null");
	  else if(st.equals(""))
		  System.out.println("\"\"");
	  else 
		  System.out.println(st);
 
 }
  
}





	}
}